﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Dao;
using Core.Entity;
using System.Data;

namespace Core.Business
{
    public class DepartmentTicketCategoryBus
    {
        private DepartmentTicketCategoryDao dao;
        public DepartmentTicketCategoryBus()
        {
            dao = new DepartmentTicketCategoryDao();
        }

        public bool insert(DepartmentTicketCategory departmentTicketCategory) {
            return dao.insert(departmentTicketCategory);
        }

        public bool update(DepartmentTicketCategory departmentTicketCategory) {
            return dao.update(departmentTicketCategory);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public DepartmentTicketCategory get(int id) {
            DataTable dt = dao.get(id);
            DepartmentTicketCategory departmentTicketCategory = new DepartmentTicketCategory();

            if (dt.Rows.Count > 0)
            {
                departmentTicketCategory.Id = Convert.ToInt32(dt.Rows[0]["DTC_ID"]);
                departmentTicketCategory.DepartmentId = Convert.ToInt32(dt.Rows[0]["DEP_ID"]);
                departmentTicketCategory.TicketCategoryId = Convert.ToInt32(dt.Rows[0]["TCK_ID"]);
            }
            return departmentTicketCategory;
        }

        public List<DepartmentTicketCategory> getAll() {
            DataTable dt = dao.getAll();
            List<DepartmentTicketCategory> list = new List<DepartmentTicketCategory>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    DepartmentTicketCategory departmentTicketCategory = new DepartmentTicketCategory();
                    departmentTicketCategory.Id = Convert.ToInt32(dr["DEP_ID"]);
                    departmentTicketCategory.DepartmentId = Convert.ToInt32(dr["DEP_ID"]);
                    departmentTicketCategory.TicketCategoryId = Convert.ToInt32(dr["TCK_ID"]);

                    list.Add(departmentTicketCategory);
                }

            }
            return list;
        }
    }
}
